#pragma once

#include "Keyboard.h"

/**
 * @brief 用于控制的键盘
 */
Keyboard_t keyboard = {
    .row = 4,
    .col = 4,
    .slugTime = 5,
    .repeatTime = 60};

/**
 * @brief 初始化键盘 IO 以及 按键码 信息
 */
void keyboard_init()
{
    keyboard_ctor(&keyboard);

    pPin rowPins = keyboard.rowPins;
    pPin colPins = keyboard.colPins;

    rowPins[0].port = KB_Row_1_GPIO_Port;
    rowPins[0].pin = KB_Row_1_Pin;
    rowPins[1].port = KB_Row_2_GPIO_Port;
    rowPins[1].pin = KB_Row_2_Pin;
    rowPins[2].port = KB_Row_3_GPIO_Port;
    rowPins[2].pin = KB_Row_3_Pin;
    rowPins[3].port = KB_Row_4_GPIO_Port;
    rowPins[3].pin = KB_Row_4_Pin;

    colPins[0].port = KB_Col_1_GPIO_Port;
    colPins[0].pin = KB_Col_1_Pin;
    colPins[1].port = KB_Col_2_GPIO_Port;
    colPins[1].pin = KB_Col_2_Pin;
    colPins[2].port = KB_Col_3_GPIO_Port;
    colPins[2].pin = KB_Col_3_Pin;
    colPins[3].port = KB_Col_4_GPIO_Port;
    colPins[3].pin = KB_Col_4_Pin;

    //初始化数字区
    uint8_t code = 1;
    for (size_t row = 0; row < 3; row++)
    {
        for (size_t col = 0; col < 3; col++)
        {
            keyboard.scan_data[row][col].code = code++;
        }
    }
    //0
    keyboard.scan_data[3][1].code = 0;
    //初始化字母区
    code = 'a';
    for (size_t row = 0; row < 4; row++)
    {
        keyboard.scan_data[row][3].code = code++;
    }
    //*号
    keyboard.scan_data[3][0].code = '*';
    //#号
    keyboard.scan_data[3][2].code = '#';
}

/**
 * @brief 按键处理程序
 * 
 * @param keyboard 键盘 
 * @param key 按键
 * @param state 按键状态
 * @param code 按键码
 */
void keyHandler(Keyboard_t keyboard, Key_t key, KeyState_t state, uint8_t code)
{
    switch (code)
    {
    case 0:
        break;
    case 1:
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
    case 7:
    case 8:
    case 9:
        break;
    case 'a':
        break;
    case 'b':
        break;
    case 'c':
        break;
    case 'd':
        break;
    case '*':
        break;
    case '#':
        break;
    }
}